package com.liu.mapper;

import com.liu.proxyDemo.User;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

@Transactional(rollbackFor = {Exception.class})
public class UserMapperImpl extends SqlSessionDaoSupport implements UserMapper{

    public UserMapperImpl() {
    }

    public List<User> selectUser() {
        UserMapper userMapper = getSqlSession().getMapper(UserMapper.class);
        //测试事务
        User user = new User("张无忌",25,1,0);
        userMapper.addUser(user);
        userMapper.deleteUser(1);
        return userMapper.selectUser();
    }

    public int addUser(User user) {
        return getSqlSession().getMapper(UserMapper.class).addUser(user);
    }

    public int deleteUser(Integer id) {
        return getSqlSession().getMapper(UserMapper.class).deleteUser(id);
    }
}
